<template>
  <div class="text">
    <div class="list">
      <p>创建时间:{{ createtime.getFullYear() + '/' + (createtime.getMonth()+1).toString() +'/' + createtime.getDate() + ' ' + createtime.getHours() + ':' + createtime.getMinutes() + ':' + createtime.getSeconds() }}</p>
      <p>运行时间:{{ runtime }}</p>
      <p>镜像:{{ imagecome }}</p>
      <p>状态:{{ runstatus }}</p>
      <p>所属主机:{{ this.host }}</p>
      <p>私网IP:{{ selfip }}</p>
      <p>公网IP:{{ publicip }}</p>
      <p>内存占用:{{ (memuse/1000000).toFixed(2)}} MB</p>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "dockerdata",
  data() {
    return {
      createtime: null,
      runtime: null,
      imagecome: null,
      runstatus: null,
      selfip: null,
      publicip: null,
      memuse: null
    }
  },
  watch: {
    docker() {
      this.refresh();
      this.timer = window.setInterval(() => {
        setTimeout(() => {
          this.refresh()
        },0)
      },5000)
    }
  },
  methods: {
    refresh: function () {
      var that = this;
      axios.get("http://127.0.0.1:5000/getdockermsg?docker=" + this.docker + "&host=" + this.host).then(
          function (res) {
            var dockerdata = res.data;
            console.log(dockerdata)
            that.createtime = new Date(dockerdata.Created*1000)
            that.runtime = dockerdata.Status
            that.imagecome = dockerdata.Image
            that.runstatus = dockerdata.State
            that.selfip = dockerdata.NetworkSettings.Networks.bridge.IPAddress
            that.publicip = dockerdata.NetworkSettings.Networks.bridge.GlobalIPv6Address
            that.memuse = dockerdata.stats.memory_stats.usage
          }
      )
      // axios.get("http://127.0.0.1:5000/getdockerstats?dockerid=" + this.dockerid).then(
      //     function (res) {
      //       var data = res.data;
      //       console.log(res);
      //       that.memuse = data["memory_stats"]["usage"]
      //       // that.data.series[0].data[0].value = (dockerdata.stats.cpu_stats.cpu_usage.usage_in_usermode /
      //       //     dockerdata.stats.cpu_stats.cpu_usage.total_usage * 100).toFixed(2);
      //
      //     }
      // )
    }
  },
  props: [
      "docker",
      "host"
  ]
}
</script>

<style scoped>
.text {
  width: 25em;
  height: 205px;
  background: #224458;
  border-radius: 10px;
}

.list {
  margin-top: 20px;
  margin-left: 20px;
  color: #9daad2;
  font-weight: bold;
}
</style>